#include <sys/wait.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

void loop_create_child_process()
{
	pid_t pid = 0;
	while(1) {
		if ( (pid=fork()) < 0) {
			fprintf(stderr, "fork failed!\n");
			sleep(10);
			continue;
		}
		if (pid == 0)
			break;
		while(wait(NULL) != pid) {
			sleep(10);
		}
		fprintf(stderr, "child process exit, create new one\n");
		sleep(1);
	}
	return ;
}

int main(int argc, char** argv)
{
	fprintf(stderr, "now create child process\n");	
	loop_create_child_process();
	fprintf(stderr, "child process start\n");	
	sleep(5);
	fprintf(stderr, "child process exit\n");	
	return 0;
}
